﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ColorPicker
{
    public partial class CPForm : Form
    {
        public CPForm()
        {
            InitializeComponent();
        }

        /// <summary>
        ///  16进制颜色值
        /// </summary>
        /// <returns></returns>
        public string GetColorHexHtml()
        {
            return CPTool.GetColorHexHtml(Control.MousePosition.X, Control.MousePosition.Y);
        }

        public Color GetColor() {

            return CPTool.GetArgb(Control.MousePosition.X, Control.MousePosition.Y);
        }

        /// <summary>
        ///  获取鼠标的位置
        /// </summary>
        /// <returns></returns>
        public Point getPoint()
        {
            return new Point()
            {
                X = Control.MousePosition.X,
                Y = Control.MousePosition.Y
            };
        }

        private void CPForm_Load(object sender, EventArgs e)
        {
            var screen = Screen.FromPoint(new Point(Cursor.Position.X, Cursor.Position.Y));
            var x = screen.WorkingArea.X + screen.WorkingArea.Width - this.Width;
            var y = screen.WorkingArea.Y + screen.WorkingArea.Height - this.Height;
            this.Location = new Point(x, y);
        }

        /// <summary>
        ///  监听快捷键
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CPForm_KeyDown(object sender, KeyEventArgs e)
        {
            if ((e.KeyCode == Keys.X) && e.Control)
            {
                //隐藏程序窗口
                Graphics g = this.CreateGraphics();
                g.FillRectangle(new SolidBrush(this.GetColor()), 60, 30, 100, 100);
                string color = this.GetColorHexHtml();
                this.colorVal.Text = string.Format("颜色值：{0}", color);
                Clipboard.SetDataObject(color);//保存到剪贴板
            }

        }

    }
}
